package com.briup.day08;

/**
 * @author 谭梦寻
 * @version 1.1
 */
public class Father {
    public int id;

//  作用：对父类中的属性进行赋值操作 （赋予初始值 0 null false）
    public Father() {
        System.out.println("父类构造器");
    }

    public Father(int id) {
        this.id = id;
    }
//    private void method() {
//        System.out.println("Father");
//    }
    public static void method1() {
        System.out.println("这是父类的静态方法");
    }
    public static void main(String[] args) {
//      当子类对象被创建时 (默认)会自动调用父类的无参构造器
        Son son = new Son();
        System.out.println(son);
        Son jack = new Son("jack", "北京");
        System.out.println(jack);
        Son joker = new Son("joker", "北京",1);
        System.out.println(joker);
        son.method1();
//        joker.method();
    }
}
class Son extends Father{
    private String name;
    private String city;

    public Son() {
        super();//显式地调用父类的无参构造器 可以不写，系统默认有
        System.out.println("子类构造器");
    }
//    @Override
    private void method() {
        System.out.println("Son");
    }

    public Son(String name, String city) {
        this.name = name;
        this.city = city;
    }
    public Son(String name, String city,int id) {
        super(id); //super调用父类构造器一定要放在第一行
        this.name = name;
        this.city = city;
//        this.id = id;//或者super.id = id

    }

    @Override
    public String toString() {
        return "Son{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", city='" + city + '\'' +
                '}';
    }
}